package tongkeyon.behavior.iterators;

import java.util.List;

/**
 * @Author: keyon <tongkeyon@163.com>
 * @Date: 2020/2/25 14:50
 * @Version 1.0
 */
public class FruitIterator implements Iterator {
    private  Basket basket;

    public FruitIterator() {
    }

    public FruitIterator(Basket basket) {
        this.basket = basket;
    }



    @Override
    public boolean hasNext() {
        return basket.getIndex()<basket.getFruitList().size();

    }

    @Override
    public Object next() {
        int index = basket.getIndex();
        List<Fruit> fruitList = basket.getFruitList();
        Fruit fruit = fruitList.get(basket.getIndex());
        basket.setIndex(++index);
        return  fruit;
    }
}
